package com.qianxx.component.activity.effects.scroll_panel.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianxx.component.R;
import com.qianxx.component.activity.MainActivity;
import com.qianxx.component.activity.effects.scroll_panel.ScrollPanelActivity;
import com.qianxx.viewlibrary.effects.scrollpanel.ScrollPanel;
import com.qianxx.viewlibrary.effects.scrollpanel.ScrollUtils;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * 点餐
 */
public class MealFragment extends Fragment {
    Unbinder unbinder;

    @BindView(R.id.rcv_top)
    RecyclerView rcvTop;
    @BindView(R.id.rcv_left)
    RecyclerView rcvLeft;
    @BindView(R.id.rcv_right)
    RecyclerView rcvRight;
    @BindView(R.id.appbar)
    AppBarLayout appbar;

    TopAdapter topAdapter;
    LeftAdapter leftAdapter;
    RightAdapter rightAdapter;

    ScrollPanel scrollPanel;
    ScrollUtils utils;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_meal, null);
        unbinder = ButterKnife.bind(this, view);

        topAdapter = new TopAdapter(getContext(), initTopData());
        rcvTop.setLayoutManager(new LinearLayoutManager(getContext(),
                LinearLayoutManager.HORIZONTAL, false));
        rcvTop.setAdapter(topAdapter);

        leftAdapter = new LeftAdapter(getContext(), initLeftData());
        rcvLeft.setLayoutManager(new LinearLayoutManager(getContext()));
        rcvLeft.setAdapter(leftAdapter);

        rightAdapter = new RightAdapter(getContext(), initRightData());
        rcvRight.setLayoutManager(new LinearLayoutManager(getContext()));
        rcvRight.setAdapter(rightAdapter);

        scrollPanel = ((ScrollPanelActivity) getActivity()).sp_menu;
        utils = new ScrollUtils();
        utils.setScrollPanel(scrollPanel);
        utils.setAppBarLayout(appbar);
        //utils.setVerticalRecycleView(rcvLeft, rcvRight);
        //utils.setHorizontalRecyclerView(rcvTop);
        return view;
    }

    private List<String> initTopData() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 8; i++) {
            list.add("咕咾肉");
        }
        return list;
    }

    private List<String> initLeftData() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 25; i++) {
            list.add("热卖");
        }
        return list;
    }

    private List<String> initRightData() {
        List<String> list = new ArrayList<>();
        for (int i = 0; i < 50; i++) {
            list.add("黄焖鸡");
        }
        return list;
    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}
